'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('minaCoupon', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        type: {
            type: Sequelize.INTEGER(2),
            allowNull: false,
        },
        title: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        description: {
            type: Sequelize.STRING(255),
        },
        quota: {
            type: Sequelize.INTEGER(6),
        },
        startAt: {
            type: Sequelize.DATE,
            allowNull: false,
        },
        endAt: {
            type: Sequelize.DATE,
            allowNull: false,
        },
        periodValid: {
            type: Sequelize.INTEGER(2),
            allowNull: false,
        },
        totalAmount: {
            type: Sequelize.INTEGER(6),
        },
        unclaimedAmount: {
            type: Sequelize.INTEGER(6),
        },
        usedAmount: {
            type: Sequelize.INTEGER(6),
            defaultValue: 0,
            allowNull: false,
        },
        status: {
            type: Sequelize.INTEGER(1),
            allowNull: false,
        },
    }, {
        freezeTableName: true,
        tableName: 'mina_coupon',
        timestamps: true,
        paranoid: true,
    })

    Model.associate = function() {
        model.MinaCoupon.belongsTo(model.Corp)
        model.Corp.hasMany(model.MinaCoupon)
    }

    return Model
}